package com.设计模式.原型模式;

import java.io.*;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/2  9:16
 * 描述:
 */
public class YuanXing implements Cloneable,Serializable {

    private String name;

    private Map<String,Object> map;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    /**
     * 作者: LCG
     * 日期: 2021/3/2  9:21
     * 描述: 浅克隆
     * @Param []
     * @Return com.设计模式.原型模式.YuanXing
     */
    public YuanXing clone01() throws CloneNotSupportedException {
        return (YuanXing)super.clone();
    }

    
    /**
     * 作者: LCG
     * 日期: 2021/3/2  9:22
     * 描述: 深克隆
     * @Param []
     * @Return com.设计模式.原型模式.YuanXing
     */
    public YuanXing deepClone() throws IOException, ClassNotFoundException {

        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);

        ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);

        YuanXing object = (YuanXing)objectInputStream.readObject();

        //关闭流
        objectInputStream.close();
        byteArrayInputStream.close();
        objectOutputStream.close();
        byteArrayOutputStream.close();

        return object;
    }

}
